package com.sxt.springcloud.sys.fallback;

import com.sxt.springcloud.sys.MenuClientService;
import com.sxt.sys.common.DataGridView;
import com.sxt.sys.common.ResultObj;
import com.sxt.sys.vo.PermissionVo;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
@Component
public class MenuClientFallbackService implements FallbackFactory {
    @Override
    public Object create(Throwable throwable) {
        return new MenuClientService() {
            @Override
            public DataGridView loadIndexLeftMenuJson(Integer userType, Integer userId) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询左侧菜单树方法失败");
            }

            @Override
            public DataGridView loadMenuManagerLeftTreeJson(PermissionVo permissionVo) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询菜单管理左侧树方法失败");
            }

            @Override
            public DataGridView loadAllMenu(PermissionVo permissionVo) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询所有菜单方法失败");
            }

            @Override
            public Map<String, Object> loadMenuMaxOrderNum() {
                Map<String, Object> map = new HashMap<>();
                map.put("失败方法","服务降级，服务器忙，请稍后重试！调用查询菜单最大值失败");
                return map;
            }

            @Override
            public ResultObj addMenu(PermissionVo permissionVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public ResultObj updateMenu(PermissionVo permissionVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public Map<String, Object> checkMenuHasChildrenNode(PermissionVo permissionVo) {
                Map<String, Object> map = new HashMap<>();
                map.put("失败方法","服务降级，服务器忙，请稍后重试！调用检查是否有子菜单失败");
                return null;
            }

            @Override
            public ResultObj deleteMenu(PermissionVo permissionVo) {
                return ResultObj.SERVER_BUSY;
            }
        };
    }
}
